import {globalAdapter} from "../../adapter/adapterInterface/model1/IGlobalAdapter";
import Configer from "../../config/Configer";
import {ConfigKey} from "../../../../constant/ConfigConstant";
import {CodeUtil} from "../../../codeAdapter/CodeUtil";

export class GlobalModel {

    static bAsync: boolean = false;

    // 游戏结束后防止重复销毁
    static bStop: boolean = false;

    static backMusicPath: string;
    static backMusicInterval: number = 1;
    static lastSetMusicTime: number;

    static chats: string[] = [];
    static chatsIndex: number = 0;

    static toasts: string[] = [];
    static toastsIndex: number = 0;

    constructor() {
    }

    static set fog(value: boolean) {
        globalAdapter.adapter.setFog(value);
    }

    static set mask(value: boolean) {
        globalAdapter.adapter.setMask(value);
    }

    static set skyModel(value: string) {
        globalAdapter.adapter.setSkyModel(value);
    }

    static set timeOfDay(num: number) {
        globalAdapter.adapter.setTimeOfDay(num);
    }

    static set timeOfDayScale(num: number) {
        globalAdapter.adapter.setTimeOfDayScale(num);
    }


    static stopBackMusic(fadeOut: boolean) {
        globalAdapter.adapter.stopBackMusic(fadeOut);
    }

    static startBackMusic(path: string) {
        globalAdapter.adapter.startBackMusic(path);
    }

    static addChat(playerName: string, chat: string) {
        const maxChatsLen = Configer.getConfig(ConfigKey.maxChatsLen);
        if (this.chats.length <=  maxChatsLen) {
        } else {
            this.chats.splice(0, 1);
        }
        this.chats.push(`${playerName}: ${chat}`);
        this.chatsIndex = this.chatsIndex + 1;
    }

    static toast(text: string, playerId: number = -1) {
        const ret = globalAdapter.adapter.toast(text, playerId);
        if (ret) {
            const maxToastLen = Configer.getConfig(ConfigKey.maxToastLen);
            if (this.toasts.length <=  maxToastLen) {
            } else {
                this.toasts.splice(0, 1);
            }
            this.toasts.push(`${text}`);
            this.toastsIndex = this.toastsIndex + 1;
        }
    }

    static getHandleId(handle: any) {
        return globalAdapter.adapter.getHandleId(handle);
    }

    static getStartTime() {
        const time = globalAdapter.adapter.getStartTime();
        if (!CodeUtil.isNullOrZero(time)) {
            return time;
        }
        return 1000000000
    }

    static addItemToAllStock(itemId: string, num: number) {
        globalAdapter.adapter.addItemToAllStock(itemId, num);
    }

    static removeItemFromAllStock(itemId: string) {
        globalAdapter.adapter.removeItemFromAllStock(itemId);
    }

}